package com.easy.controllor;


import com.easy.bean.*;
import com.easy.service.TicketService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 车票查询控制器
 */
@RestController
@CrossOrigin
@RequestMapping("/ticket")
public class TicketController {

    @Autowired
    private TicketService ticketService;

    @GetMapping
    public List<TrainTicketQueryVO> queryTickets(TicketQueryParam param) {
        return ticketService.queryTickets(param);
    }
    @GetMapping("/page")
    public Result page(Page page, TicketQueryParam param){
        //查询一共多少条数据
        //查询当前页要显示的数据
        //封装到page里面去
        ticketService.page(page, param);
        //返回page对象
        return Result.success(page);
    }

    @PostMapping("/submit")
    public Result submit(@RequestBody OrderDetail param) {
        OrderDetail submit = ticketService.submit(param);
        return Result.success(submit);
    }




    @GetMapping("/statistics")
    public Result getTicketStatisticsByDate(LocalDate date){
        List<RemainTickets> ticketStatisticsByDate = ticketService.getTicketStatisticsByDate(date);
        return Result.success(ticketStatisticsByDate);
    }






}

